package Server.Sessions;

import java.util.LinkedList;

import shared.Messages.Message;

public class OutboundMessages {
	private LinkedList<Message> messages = new LinkedList<Message>();

	public synchronized void addMessage(Message s) {
		messages.add(s);
		this.notifyAll();
	}

	public synchronized Message getMessage() { 
		try {
			while (messages.isEmpty())
				this.wait(); 
		} catch (InterruptedException e) {
			System.out.println("Wait katkestatud!");
		}

		Message s = messages.getFirst();
		messages.removeFirst();
		return s;
	}
}